package org.ggn.scoreanalyze.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

/** 主面板类，用于显示数据
 * Created by guin_guo on 2015/12/10.
 */
public class ScorePanel implements Serializable {
    private String clazz;
    private String name;
    private List<Student> students;
    private int highest;
    private int lowest;
    private double average;
    private int sum;//总分数
    private int yx;
    private int lh;
    private int zd;
    private int jg;
    private int bjg;
    private double pyx;
    private double plh;
    private double pzd;
    private double pjg;
    private double pbjg;
    private String filePath;

    public ScorePanel() {
        students = new ArrayList<Student>();
    }

    public ScorePanel(String clazz, String name, List<Student> students) {
        this.clazz = clazz;
        this.name = name;
        this.students = students;
    }

    /**
     * 把学生的List转成Vector
     * @return
     */
    public Vector<Vector<String>> getDatas(){
        Vector row = new Vector();
        for (Student value : students) {
            Vector r = new Vector(3);
            r.add(value.getAccount());
            r.add(value.getName());
            r.add(value.getScore());
            row.add(r);
        }
        return row;
    }

    /**
     * 查询信息的方法
     * @param param
     * @return
     */
    public Vector<Vector<String>> findDatas(String param){
        Vector row = new Vector();
        for (Student value : students) {
            if (value.getAccount().contains(param) || String.valueOf(value.getScore()).contains(param) || value.getName().contains(param)) {
                Vector r = new Vector(3);
                r.add(value.getAccount());
                r.add(value.getName());
                r.add(value.getScore());
                row.add(r);
            }
        }
        return row;
    }

    /**
     * 数据处理方法
     */
    public void deal() {
        for (Student student : this.students) {
            int score = student.getScore();
            if (highest < score ) {
                highest = score;
            }
            if (lowest == 0) lowest = highest;
            if (lowest > score) {
                lowest = score;
            }
            sum += student.getScore();

            //几个数据区间
            if (90 <= score && score <= 100) {
                yx++;
            } else if (80 <= score && score < 90) {
                lh++;
            } else if (70 <= score && score < 80) {
                zd++;
            } else if (60 <= score && score <= 70) {
                jg++;
            } else {
                bjg++;
            }
        }
        pyx = yx * 1.0 / students.size() *100;
        plh = lh * 1.0 / students.size() *100;
        pzd = zd * 1.0 / students.size() *100;
        pjg = jg * 1.0 / students.size() *100;
        pbjg = bjg * 1.0 / students.size() *100;
        average = sum*1.0 / students.size();
    }

    public String getClazz() {
        return clazz;
    }

    public void setClazz(String clazz) {
        this.clazz = clazz;
    }

    public String getFilePath() {
        return filePath;
    }

    public void setFilePath(String filePath) {
        this.filePath = filePath;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public List<Student> getStudents() {
        return students;
    }

    public void setStudents(List<Student> students) {
        this.students = students;
    }

    public int getHighest() {
        return highest;
    }

    public void setHighest(int highest) {
        this.highest = highest;
    }

    public int getLowest() {
        return lowest;
    }

    public void setLowest(int lowest) {
        this.lowest = lowest;
    }

    public double getAverage() {
        return average;
    }

    public void setAverage(double average) {
        this.average = average;
    }

    public int getSum() {
        return sum;
    }

    public void setSum(int sum) {
        this.sum = sum;
    }

    public int getYx() {
        return yx;
    }

    public void setYx(int yx) {
        this.yx = yx;
    }

    public int getLh() {
        return lh;
    }

    public void setLh(int lh) {
        this.lh = lh;
    }

    public int getZd() {
        return zd;
    }

    public void setZd(int zd) {
        this.zd = zd;
    }

    public int getJg() {
        return jg;
    }

    public void setJg(int jg) {
        this.jg = jg;
    }

    public int getBjg() {
        return bjg;
    }

    public void setBjg(int bjg) {
        this.bjg = bjg;
    }

    public double getPyx() {
        return pyx;
    }

    public void setPyx(double pyx) {
        this.pyx = pyx;
    }

    public double getPlh() {
        return plh;
    }

    public void setPlh(double plh) {
        this.plh = plh;
    }

    public double getPzd() {
        return pzd;
    }

    public void setPzd(double pzd) {
        this.pzd = pzd;
    }

    public double getPjg() {
        return pjg;
    }

    public void setPjg(double pjg) {
        this.pjg = pjg;
    }

    public double getPbjg() {
        return pbjg;
    }

    public void setPbjg(double pbjg) {
        this.pbjg = pbjg;
    }
}
